/** ###################################################################
**     Filename  : parking.c
**     Project   : parking
**     Processor : MC9S12XS128MAL
**     Version   : Driver 01.14
**     Compiler  : CodeWarrior HCS12X C Compiler
**     Date/Time : 2013-2-23, 14:36
**     Abstract  :
**         Main module.
**         This module contains user's application code.
**     Settings  :
**     Contents  :
**         No public methods
**
** ###################################################################*/
/* MODULE parking */

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "LT_LEFT.h"
#include "LT_RIGHT.h"
#include "LT_STOP_LEFT.h"
#include "LT_TIMER.h"
#include "LT_STOP_RIGHT.h"
#include "INF.h"
#include "PARK_TIMER.h"
#include "MEMORY.h"
#include "AD.h"
#include "DRV_BACK.h"
#include "DRV_TIMER.h"
#include "DRV_MEN.h"
#include "DRV_SERVO.h"
#include "DRV_PWM.h"
#include "AS.h"
#include "DRV_SERVO_TIMER.h"
#include "HMI_PA.h"
#include "HMI_ED.h"
#include "HMI_HIGH_BYTE.h"
#include "HMI_LOW_BYTE.h"
#include "HMI_SPIN.h"
#include "HMI_SPIN_DIR.h"
#include "HMI_IRQ.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
#include "Types.h"
#include "Hmi.h"
#include "Encoder.h"
#include "Drv.h"
#include "EM.h"
#include "Communication.h"
#include "Test.h"
#include <stdio.h>
#include "CommandSystem.h"
#include "ParkControl.h"
void main(void)
{
  /* Write your local variable definition here */
  	int step = 0;
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
    
    HmiShowNumber(step++);
	HmiInitSystem();
	HmiShowNumber(step++);
	EncoderInitial();
	HmiShowNumber(step++);
	EMInit();
	HmiShowNumber(step++);
	CSInit();
	HmiShowNumber(step++);
	PCInit();
	HmiShowNumber(step++);
	TstCheckFlag();
	HmiShowNumber(step++);
							
/*	for (;;){
		char str[30];
		U16 len;
		(void)sprintf(str, "1max=%u,2max=%u\n", Vem_1_max, Vem_2_max);
		len = strlen(str);
		ASSendData((U8*)&str[0], len);
		Cpu_Delay100US(1000);
		
	}		  */
/*	DrvEnableMotorControl();
	for (;;){
		S16 ss;	
		ss = (S16)HmiWaitForDigit();	
		DrvSetSpeedMotor(ss);
	}
							*/
							
//	DRV_SERVO_SetDuty(DrvServoMiddle); 		
 
 	

		
	/*    
	for (;;){
		U8 left, right;
		S16 value;
		U16 len;
		char str[50];
		
		left = EMLeftFrontValue;
		right = EMRightFrontValue;
		value = EMGetValue();
		(void)sprintf(str, "Left = %u\tRight = %u\tValue=%d\n", left, right, value);
		len = strlen(str);
		ASSendData((U8*)&str[0], len);
		Cpu_Delay100US(200);
	}  */
	   
  
		 
/*	for (;;){
		U16 c;
		c = HmiWaitForNumberEx(0, 0, 0, 1);
		TstInitParkControl();
		TstParkControl();	
		
	}   */
/*  for(;;){
  	
//	TstEncoderScale();
	TstParkControlCalibration();
	
  }	*/	 
/*  for (;;){
  	TstTestDrv(&TstEMBackward, -15);	
  	
  }	  */
  
  //TstServoAndDrv();
   
  // TstDrv();
  /*for (;;){
//  	TstTest(&TstInf);	
//		TstTest(&TstEncoder);
		TstEncoderScale();
  } 
  	 */
  
  	 
 //	TstDrvSpeed();  
//	TstEm(); 
//	TstEMDriveBackward();	  

//	TstLights();
//	TstInitEmBackwardControl();  
	CSEntry();	

  
	   
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END parking */
/*
** ###################################################################
**
**     This file was created by Processor Expert 3.02 [04.44]
**     for the Freescale HCS12X series of microcontrollers.
**
** ###################################################################
*/
